
// #ifndef VUE3
import Vue from 'vue'
import App from './App'

// 导入vuex
import store from './store/store.js'
// 导入网络请求库
import { $http } from '@escook/request-miniprogram'


// 配置请求根路径
$http.baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
// $http.baseUrl = 'https://uinav.com/api/public/v1'

// 请求开始之前
$http.beforeRequest = function (options) {
  uni.showLoading({
    title: '数据加载中...',
  })
  
  // 识别需要认证的接口
  if(options.url.includes('/my/')) {
    // 请求头添加token
    options.header = {
      Authorization: store.state.m_user.token 
    }
  }
}

// 请求完成之后
$http.afterRequest = function () {
  uni.hideLoading()
}

// 将$http挂载到uni全局对象
uni.$http = $http

// 数据获取失败提示
uni.$showMsg = function (title = '数据加载失败！', duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon: 'none',
  })
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App, 
    store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif